package zozopo.flow.operations;

import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import zozopo.comm.CNSpell;
import zozopo.database.BusiDatabaseManager;
import zozopo.database.SqlMachine;
import zozopo.flow.comm.FlowCode;
import zozopo.operations.comm.OperatingService;
import zozopo.warehouse.operations.GoodsTB;
import zozopo.warehouse.operations.PurchaselistTB;
import zozopo.warehouse.operations.ReceiptlistTB;

public class RecordlistOS extends OperatingService{
	public RecordlistOS(Connection conn){
		super(conn);
	}
	
	public RecordlistOS(){
		this.databaseConnection = new BusiDatabaseManager();
		this.conn = databaseConnection.getConnection();
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public List<RecordlistTB> selectListBySql(String sql){
		List<RecordlistTB> recordlistList = null;
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		
		if(resultSet != null){
				try {
					recordlistList = new ArrayList<RecordlistTB>();
					while(resultSet.next()){
						RecordlistTB recordlist = new RecordlistTB();
						
						recordlist.setCnname_recordlist(resultSet.getString(RecordlistTB.CNNAME_RECORDLIST));
						
						recordlist.setCode_recordlist(resultSet.getString(RecordlistTB.CODE_RECORDLIST));
						
						
						recordlist.setDate_recordlist(resultSet.getString(RecordlistTB.DATE_RECORDLIST));
						
						recordlist.setEnname_recordlist(resultSet.getString(RecordlistTB.ENNAME_RECORDLIST));
						recordlist.setId_recordlist(resultSet.getInt(RecordlistTB.ID_RECORDLIST));
						
						recordlist.setKind_recordlist(resultSet.getString(RecordlistTB.KIND_RECORDLIST));
						recordlist.setKindid_recordlist(resultSet.getInt(RecordlistTB.KINDID_RECORDLIST));
						
						recordlist.setDoublevalue_recordlist(resultSet.getDouble(RecordlistTB.DOUBLEVALUE_RECORDLIST));
						
						recordlist.setRemark_recordlist(resultSet.getString(RecordlistTB.REMARK_CONFIG));
						recordlist.setFlowflag_recordlist(resultSet.getString(RecordlistTB.FLOWFLAG_RECORDLIST));
						
						recordlist.setUseremail_recordlist(resultSet.getString(RecordlistTB.USEREMAIL_RECORDLIST));
						recordlist.setUsername_recordlist(resultSet.getString(RecordlistTB.USERNAME_RECORDLIST));
						recordlist.setValue_recordlist(resultSet.getInt(RecordlistTB.VALUE_RECORDLIST));
						recordlist.setNextvalue_recordlist(resultSet.getInt(RecordlistTB.NEXTVALUE_RECORDLIST));
						recordlistList.add(recordlist);
					}
					resultSet.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		}
		
		return recordlistList;
	
	}
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	public boolean upadte(RecordlistTB recordlist){
		SqlMachine sqlMachine = new SqlMachine(conn);
		HashMap<String, Object> updateMap = new HashMap<String, Object>();
		updateMap.put(RecordlistTB.ID_RECORDLIST, recordlist.getId_recordlist());
		updateMap.put(RecordlistTB.CHARVALUE_RECORDLIST, recordlist.getCharvalue_recordlist());
		
		
		return sqlMachine.updateRow(RecordlistTB.TABLE_NAME, updateMap, RecordlistTB.ID_RECORDLIST, recordlist.getId_recordlist());
	}
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	public boolean upadte(int id,String flowFlag){
		SqlMachine sqlMachine = new SqlMachine(conn);
		
		HashMap<String, Object> updateMap = new HashMap<String, Object>();
		//updateMap.put(RecordlistTB.ID_RECORDLIST, id);
		updateMap.put(RecordlistTB.FLOWFLAG_RECORDLIST, flowFlag);
		
		 
		return sqlMachine.updateRow(RecordlistTB.TABLE_NAME, updateMap, RecordlistTB.ID_RECORDLIST, id);
	}
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	public boolean upadte(int id,int nextValue){
		SqlMachine sqlMachine = new SqlMachine(conn);
		
		HashMap<String, Object> updateMap = new HashMap<String, Object>();
		//updateMap.put(RecordlistTB.ID_RECORDLIST, id);
		updateMap.put(RecordlistTB.NEXTVALUE_RECORDLIST, nextValue);
		
		 
		return sqlMachine.updateRow(RecordlistTB.TABLE_NAME, updateMap, RecordlistTB.ID_RECORDLIST, id);
	}
	
	/**
	 * @version 1.0
	 * @author gee
	 */
	public boolean cancel(int id){
		SqlMachine sqlMachine = new SqlMachine(conn);
		
		HashMap<String, Object> updateMap = new HashMap<String, Object>();
		//updateMap.put(RecordlistTB.ID_RECORDLIST, id);
		updateMap.put(RecordlistTB.ISCANCEL_RECORDLIST, true);
		
		 
		return sqlMachine.updateRow(RecordlistTB.TABLE_NAME, updateMap, RecordlistTB.ID_RECORDLIST, id);
	}
	
	/**
	 * @version 1.0
	 * @author gee
	 */
	public boolean keepback(int id){
		SqlMachine sqlMachine = new SqlMachine(conn);
		
		HashMap<String, Object> updateMap = new HashMap<String, Object>();
		//updateMap.put(RecordlistTB.ID_RECORDLIST, id);
		updateMap.put(RecordlistTB.ISCANCEL_RECORDLIST, false);
		
		 
		return sqlMachine.updateRow(RecordlistTB.TABLE_NAME, updateMap, RecordlistTB.ID_RECORDLIST, id);
	}
	
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public int getRowNum(){
		
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + RecordlistTB.TABLE_NAME ;
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public int getRowNum(String flowFlag){
		
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + RecordlistTB.TABLE_NAME 
		+" where " + RecordlistTB.FLOWFLAG_RECORDLIST + " ='"+flowFlag+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public int getRowNum(String kind,String flowCode,String flowFlag){
		
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + RecordlistTB.TABLE_NAME 
		+" where " + RecordlistTB.KIND_RECORDLIST + " ='"+kind+"' "
		+ " AND " + RecordlistTB.FLOWFLAG_RECORDLIST + " ='"+flowFlag+"'"
		+" AND " + RecordlistTB.CODE_RECORDLIST + " ='"+flowCode+"'";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	public List<RecordlistTB> selectBySearchStr(String searchStr,int beginPageNum,int pageSize){
		String sql = "select * from "+GoodsTB.TABLE_NAME+" WHERE  "
		+GoodsTB.NAME_GOODS+" LIKE '%"+searchStr+"%'"
		+" OR "+GoodsTB.ID_GOODS+" LIKE '%"+searchStr+"%'"
		+" OR "+GoodsTB.CNSPELL_GOODS+" LIKE '%"+searchStr+"%'"
		+" OR "+GoodsTB.FWCNSPELL_GOODS+" LIKE '%"+searchStr+"%'"
		+" limit "+beginPageNum+","+pageSize; 
		//ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		return selectListBySql(sql);
	}
	/**
	 * @version 1.0
	 * @see 
	 */
	public int getRowNumForSearchStr(String searchStr){
		
		int rowNum = 0;
		String sql = "select count(*) as rowNum from " + GoodsTB.TABLE_NAME +" WHERE  "
		+GoodsTB.NAME_GOODS+" LIKE '%"+searchStr+"%'"
		+" OR "+GoodsTB.ID_GOODS+" LIKE '%"+searchStr+"%'"
		+" OR "+GoodsTB.CNSPELL_GOODS+" LIKE '%"+searchStr+"%'"
		+" OR "+GoodsTB.FWCNSPELL_GOODS+" LIKE '%"+searchStr+"%'"; 
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	public List<RecordlistTB> selectAll(int beginPageNum,int pageSize){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  +" ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC limit "+beginPageNum+","+pageSize; 
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	public List<RecordlistTB> selectAll(){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  +" ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC "; 
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	public List<RecordlistTB> select(String kind,int kindid){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
		+" where " + RecordlistTB.KIND_RECORDLIST + " ='"+kind+"'"
		+ " AND " + RecordlistTB.KINDID_RECORDLIST + " ='"+kindid+"'"
		+" ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC "; 
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	public List<RecordlistTB> select(String kind){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
		+" where " + RecordlistTB.KIND_RECORDLIST + " ='"+kind+"'"
		+" ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC "; 
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	public List<RecordlistTB> selectForReport(String kind,int beginPageNum,int pageSize){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
			+ " where " + RecordlistTB.KIND_RECORDLIST + " ='"+kind+"'"
			+ " AND " + RecordlistTB.NEXTVALUE_RECORDLIST + "=-1"
			+ " ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC "
			+ " limit "+beginPageNum+","+pageSize; 
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	public List<RecordlistTB> selectForReport(List<ReceiptlistTB> receiptlistList){
		
		String inStr = "(";
		boolean isFirst = true;
		
		if(receiptlistList == null){
			return null;
		}
		
		for(ReceiptlistTB receiptlist:receiptlistList){
			if(isFirst){
				inStr += receiptlist.getId_receiptlist();
				isFirst = false;
			}else{
				inStr += "," + receiptlist.getId_receiptlist();
			}
		}
		inStr +=")";
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
			+ " where " + RecordlistTB.KINDID_RECORDLIST + " IN "+inStr+""
			+ " AND " + RecordlistTB.FLOWFLAG_RECORDLIST +"=1"
			+ " AND " + RecordlistTB.KIND_RECORDLIST  +"='"+ FlowCode.WAREHOUSE_RECEIPTLIST+"'"; 
		
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	public List<RecordlistTB> selectForPurchaselistList(List<PurchaselistTB> purchaselistList){
		
		String inStr = "("; 
		boolean isFirst = true;
		
		if(purchaselistList == null){
			return null;
		}
		
		for(PurchaselistTB list:purchaselistList){
			if(isFirst){
				inStr += list.getId_purchaselist();
				isFirst = false;
			}else{
				inStr += "," + list.getId_purchaselist();
			}
		}
		inStr +=")";
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
			+ " where " + RecordlistTB.KINDID_RECORDLIST + " IN "+inStr+""
			+ " AND " + RecordlistTB.FLOWFLAG_RECORDLIST +"=1" 
			+ " AND " + RecordlistTB.KIND_RECORDLIST  +"='"+ FlowCode.WAREHOUSE_PURCHASELIST+"'"; 
		
		allList = selectListBySql(sql);
		
		return allList;
	}
	

	public Map<Integer,RecordlistTB> getRecordlistMapByInStr(String inStr){
		
		if(inStr.length() < 3){
			return null;
		}
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
			+ " where " + RecordlistTB.KINDID_RECORDLIST + " IN "+inStr+""
			+ "AND " + RecordlistTB.FLOWFLAG_RECORDLIST + "=1"; 
		
		
		allList = selectListBySql(sql);
		
		Map<Integer,RecordlistTB> recorlistMap = new HashMap<Integer,RecordlistTB>();
		
		for(RecordlistTB recordlist:allList){
			recorlistMap.put(recordlist.getKindid_recordlist(), recordlist);
		}
		
		return recorlistMap;
	}
	
	
	public List<RecordlistTB> select(String kind,String flowCode,String flowFlag,int beginPageNum,int pageSize){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
		+" where " + RecordlistTB.KIND_RECORDLIST + " ='"+kind+"' "
		+" AND " + RecordlistTB.FLOWFLAG_RECORDLIST + " ='"+flowFlag+"'"
		+" AND " + RecordlistTB.CODE_RECORDLIST + " ='"+flowCode+"'"
		+" ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC limit "+beginPageNum+","+pageSize; 
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	public List<RecordlistTB> selectByFlag(String flowFlag,int beginPageNum,int pageSize){
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
		+" where "
		+ RecordlistTB.FLOWFLAG_RECORDLIST + " ='"+flowFlag+"'"
		+" ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC limit "+beginPageNum+","+pageSize; 
		allList = selectListBySql(sql);
		
		return allList;
	}
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	
	public boolean isExist(String kind,int kindid) throws IOException, NoSuchAlgorithmException, SQLException{
		String sql = "select * from "+RecordlistTB.TABLE_NAME+" where "+RecordlistTB.KIND_RECORDLIST+"='"+kind+"' and "+RecordlistTB.KINDID_RECORDLIST+"="+kindid+"";
		//System.out.println(sql.toString());
		if(logger.isDebugEnabled()){
			logger.debug("isRealUserByEmail() sql:"+sql.toString());
		}
		boolean eResult = false;
		try {
			ResultSet result = databaseConnection.executeQuery(conn, sql);
			if(result.next()){
				eResult = true;
			}
			result.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return eResult;
	}
	
	/**
	 * @version 1.0
	 * @see 
	 */
	public boolean insert(RecordlistTB recordlist){
		SqlMachine sqlMachine = new SqlMachine(conn);
		HashMap<String, Object> insertMap = new HashMap<String, Object>();

		insertMap.put(RecordlistTB.CNNAME_RECORDLIST, recordlist.getCnname_recordlist());
		insertMap.put(RecordlistTB.CODE_RECORDLIST, recordlist.getCode_recordlist());
		//insertMap.put(RecordlistTB.ENNAME_RECORDLIST, recordlist.getBarcode_goods());
		insertMap.put(RecordlistTB.KIND_RECORDLIST, recordlist.getKind_recordlist());
		insertMap.put(RecordlistTB.KINDID_RECORDLIST, recordlist.getKindid_recordlist());
		insertMap.put(RecordlistTB.REMARK_CONFIG, recordlist.getRemark_recordlist());
		insertMap.put(RecordlistTB.USEREMAIL_RECORDLIST, recordlist.getUseremail_recordlist());
		
		insertMap.put(RecordlistTB.USERNAME_RECORDLIST, recordlist.getUsername_recordlist());
		insertMap.put(RecordlistTB.VALUE_RECORDLIST, recordlist.getValue_recordlist()); 
		insertMap.put(RecordlistTB.NEXTVALUE_RECORDLIST, recordlist.getNextvalue_recordlist()); 

		insertMap.put(RecordlistTB.DOUBLEVALUE_RECORDLIST, recordlist.getDoublevalue_recordlist()); 
		
		insertMap.put(RecordlistTB.FLOWFLAG_RECORDLIST, recordlist.getFlowflag_recordlist()); 
		
		return sqlMachine.insertRow(RecordlistTB.TABLE_NAME, insertMap);
	}
	
	public RecordlistTB getNewValueByKind(String kind){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
		+ " where " + RecordlistTB.KIND_RECORDLIST + " ='" + kind + "' "
		+" ORDER BY "+RecordlistTB.ID_RECORDLIST; 
		allList = selectListBySql(sql);
		RecordlistTB recordlist = allList.get(0);
		return recordlist;
	}
	
	public RecordlistTB getNewValue(String kind,int kindid){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
		+ " where " + RecordlistTB.KIND_RECORDLIST + " ='" + kind + "' "
		+ " AND " + RecordlistTB.KINDID_RECORDLIST + " =" + kindid + " "
		 + " AND " + RecordlistTB.FLOWFLAG_RECORDLIST + "!=9 "
		+" ORDER BY "+RecordlistTB.ID_RECORDLIST+" DESC "; 
		
		RecordlistTB recordlist;
		allList = selectListBySql(sql);
		if(allList == null){
			recordlist = new RecordlistTB();
			recordlist.setCnname_recordlist("未加入流程");
			recordlist.setValue_recordlist(-1);
		}else if(allList.size() == 0){
			recordlist = new RecordlistTB();
			recordlist.setCnname_recordlist("未加入流程");
			recordlist.setValue_recordlist(-1);
		}else{
			recordlist = allList.get(0);
		}
		
		return recordlist;
	}
	
	public RecordlistTB getCurrentValue(String kind,int kindid){
		
		List<RecordlistTB> allList = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME  
		+ " where " + RecordlistTB.KIND_RECORDLIST + " ='" + kind + "' "
		+ " AND " + RecordlistTB.KINDID_RECORDLIST + " =" + kindid + " "
		+ " AND " + RecordlistTB.FLOWFLAG_RECORDLIST + " ='1'";
		
		
		RecordlistTB recordlist;
		allList = selectListBySql(sql);
		if(allList == null || allList.size() == 0){
			recordlist = new RecordlistTB();
			recordlist.setCnname_recordlist("未加入流程");
			recordlist.setValue_recordlist(-1);
		}else{
			recordlist = allList.get(0);
		}
		
		return recordlist;
	}
	
	
	
	
	
	public Map<Integer,RecordlistTB> getRecordlistMapByKindForReport(String kind,int beginPageNum,int pageSize){
		
		List<RecordlistTB> recordlistList = selectForReport(kind,beginPageNum,pageSize);
		
		Map<Integer,RecordlistTB> recorlistMap = new HashMap<Integer,RecordlistTB>();
		
		for(RecordlistTB recordlist:recordlistList){
			recorlistMap.put(recordlist.getKindid_recordlist(), recordlist);
		}
		
		return recorlistMap;
	}
	
	public Map<Integer,RecordlistTB> getRecordlistMapByKindForPurchaselistList(List<PurchaselistTB> purchaselistList){
		
		List<RecordlistTB> recordlistList = selectForPurchaselistList(purchaselistList);
		if(recordlistList == null){
			return null;
		}
		
		Map<Integer,RecordlistTB> recorlistMap = new HashMap<Integer,RecordlistTB>();
		
		for(RecordlistTB recordlist:recordlistList){
			recorlistMap.put(recordlist.getKindid_recordlist(), recordlist);
		}
		
		return recorlistMap;
	}
	
	public Map<Integer,RecordlistTB> getRecordlistMapByKindForReport(List<ReceiptlistTB> receiptlistList){
		
		List<RecordlistTB> recordlistList = selectForReport(receiptlistList);
		if(recordlistList == null){
			return null;
		}
		
		Map<Integer,RecordlistTB> recorlistMap = new HashMap<Integer,RecordlistTB>();
		
		for(RecordlistTB recordlist:recordlistList){
			recorlistMap.put(recordlist.getKindid_recordlist(), recordlist);
		}
		
		return recorlistMap;
	}
	
	
	
	
	public RecordlistTB getRecordlistById(int id){
		RecordlistTB recordlist = null;
		String sql = "SELECT * FROM " + RecordlistTB.TABLE_NAME
		+ " WHERE " + RecordlistTB.ID_RECORDLIST + "=" + id;
		List<RecordlistTB> recordlistList = selectListBySql(sql);
		
		//Map<Integer,RecordlistTB> recorlistMap = new HashMap<Integer,RecordlistTB>();
		
		for(RecordlistTB recordlistFor:recordlistList){
			recordlist = recordlistFor;
		}
		
		return recordlist;
	}
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	public int countFlowNumberByFlowCode(String code){
		int rowNum = 0;
		
		String sql = "SELECT COUNT(*) AS rowNum " +
		"FROM receiptlist_warehouse  " +
		" WHERE id_receiptlist " + 
		" IN ( SELECT kindid_recordlist " +
		"FROM recordlist_flow WHERE code_recordlist='" +
		code+ "' AND flowflag_recordlist=1 ) " +
		"AND iscancel_receiptlist=false"; 
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					rowNum = resultSet.getInt("rowNum");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return rowNum;
	}
	
	/**
	 * @version 1.0
	 * @author Gee
	 */
	public List<RecordlistTB> countDailyCodeNumber(String email,String begindate,String enddate){
	
		List<RecordlistTB> recordlistList = null;
		
		String sql = "SELECT code_recordlist,cnname_recordlist, COUNT(code_recordlist) AS intvalue_recordlist,DATE_FORMAT(date_recordlist, '%Y-%m-%d') AS date_recordlist " +
				"FROM recordlist_flow " +
				"WHERE useremail_recordlist='"+email+"' " +
				"AND date_recordlist BETWEEN '"+begindate+"' " +
				"AND '"+enddate+"'" +
				"AND iscancel_recordlist=false  " +
				"GROUP BY code_recordlist,DATE_FORMAT(date_recordlist, '%Y-%m-%d')  " +
				"ORDER BY  date_recordlist DESC";
		
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			recordlistList = new ArrayList<RecordlistTB>();
			
			try {
				
				while(resultSet.next()){
					
					RecordlistTB recordlist = new RecordlistTB();
					
					recordlist.setCnname_recordlist(resultSet.getString(RecordlistTB.CNNAME_RECORDLIST));
					
					recordlist.setCode_recordlist(resultSet.getString(RecordlistTB.CODE_RECORDLIST));
					
					
					recordlist.setDate_recordlist(resultSet.getString(RecordlistTB.DATE_RECORDLIST));
				
					recordlist.setIntvalue_recordlist(resultSet.getInt(RecordlistTB.INTVALUE_RECORDLIST));
				
					recordlistList.add(recordlist);
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		

		return recordlistList;
	}
	
	
	/**
	 * @version 1.0
	 * @author Shea
	 */
	public double sumPurchaselistByFlowCode(String code){
		double total = 0;
		
		String sql = "SELECT SUM(total_purchaselist) AS total " +
		"FROM purchaselist_warehouse  " +
		" WHERE id_purchaselist  " +
		" IN ( SELECT kindid_recordlist " +
		"FROM recordlist_flow WHERE code_recordlist='" +
		code+ "' AND flowflag_recordlist=1 ) " +
		"AND iscancel_purchaselist=false";
		
		ResultSet resultSet = databaseConnection.executeQuery(conn, sql);
		if(resultSet != null){
			try {
				
				while(resultSet.next()){
					total = resultSet.getInt("total");
				}
				resultSet.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return total;
	}
}
